﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Web.Configuration;
using System.IO;

/// <summary>
/// Summary description for DBAccess
/// </summary>
public class DBAccess
{
    string connectionString;
    private SqlConnection connect;
        
	public SqlConnection GetCon()
        {
           connectionString = WebConfigurationManager.ConnectionStrings["AppleShopConnectionString"].ToString();
           connect = new SqlConnection(connectionString);
           return new SqlConnection(connectionString);
        }
    public bool CheckIDProduct(string productID)
    {

        SqlConnection con = GetCon();
        if (con.State == ConnectionState.Open)
        {
            con.Close();
        }
        SqlCommand cmd = new SqlCommand("select * from Product where ProductsID='" + productID + "'", con);
        con.Open();
        SqlDataReader dr = cmd.ExecuteReader();
        if (dr.Read())
        {

            return true;
        }
        else
        {
            con.Close();
            return false;
        }
    }
    public bool CheckProductDetail(string img)
    {

        SqlConnection con = GetCon();
        if (con.State == ConnectionState.Open)
        {
            con.Close();
        }
        SqlCommand cmd = new SqlCommand("select * from ProductDetails where DetailsImage='" + img + "'", con);
        con.Open();
        SqlDataReader dr = cmd.ExecuteReader();
        if (dr.Read())
        {

            return true;
        }
        else
        {
            con.Close();
            return false;
        }
    }
    public bool CheckProduct(string img)
    {

        SqlConnection con = GetCon();
        if (con.State == ConnectionState.Open)
        {
            con.Close();
        }
        SqlCommand cmd = new SqlCommand("select * from Product where ProductsImage='" + img + "'", con);
        con.Open();
        SqlDataReader dr = cmd.ExecuteReader();
        if (dr.Read())
        {

            return true;
        }
        else
        {
            con.Close();
            return false;
        }
    }
}